package com.cpr.ams.service.impl;

import com.cpr.ams.bean.ServiceRecord;
import com.cpr.ams.bean.ServiceResults;
import com.cpr.ams.bean.extend.OrderExtend;
import com.cpr.ams.bean.extend.ServiceRecordExtend;
import com.cpr.ams.mapper.ServiceRecordMapper;
import com.cpr.ams.mapper.ServiceResultsMapper;
import com.cpr.ams.mapper.extend.CheckUpExtendMapper;
import com.cpr.ams.service.ICheckUpService;
import com.jacky.base.utils.PageVM;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CheckUpServiceImpl implements ICheckUpService {
    @Autowired
    private ServiceRecordMapper serviceRecordMapper;
    @Autowired
    private CheckUpExtendMapper checkUpExtendMapper;
    @Autowired
    private ServiceResultsMapper serviceResultsMapper;
    @Override
    public void saveOrUpdateCheckUp(ServiceRecord serviceRecord) {
        if (serviceRecord.getId()!=null){
            serviceRecordMapper.updateByPrimaryKeySelective(serviceRecord);
        }else {
            serviceRecordMapper.insert(serviceRecord);
        }
    }

    @Override
    public PageVM<ServiceRecordExtend> query(Integer page, Integer pageSize, String type) {
        List<ServiceRecordExtend> list=checkUpExtendMapper.query(page,pageSize,type);
        long total =checkUpExtendMapper.count(type);
        return new PageVM<>(page, pageSize, total, list);
    }

    @Override
    public void saveOrUpdateResult(ServiceResults serviceResults) {
        if (serviceResults.getId()!=null){
            serviceResultsMapper.updateByPrimaryKeySelective(serviceResults);
            ServiceRecord sr=new ServiceRecord();
            sr.setId(serviceResults.getServiceId());
            sr.setServiceStatus("已解决");
            saveOrUpdateCheckUp(sr);
        }else {
            serviceResultsMapper.insert(serviceResults);
        }
    }
}
